document.addEventListener('DOMContentLoaded', function() {
    console.log("DOM fully loaded and parsed"); // 调试信息

    document.getElementById('moveRandom').onclick = function() {
        console.log("Move Random Element button clicked"); // 调试信息
        chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
            chrome.scripting.executeScript({
                target: { tabId: tabs[0].id },
                function: pointer.move_to_random_element_and_click // 直接调用函数
            });
        });
    };

    document.getElementById('ocr').onclick = function() {
     
        window.location.href = 'data/interface/index.html';
        };
    document.getElementById('moveToSelector').onclick = function() {
        const selector = document.getElementById('selectorInput').value;
        console.log("Moving to selector: " + selector); // 调试信息
        chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
            chrome.scripting.executeScript({
                target: { tabId: tabs[0].id },
                function: pointer.move_mouse_to_element,
                args: [selector] // 传递参数
            });
        });
    };

    document.getElementById('clickBySelector').onclick = function() {
        const selector = document.getElementById('selectorInput').value;
        console.log("Clicking selector: " + selector); // 调试信息
        chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
            chrome.scripting.executeScript({
                target: { tabId: tabs[0].id },
                function: pointer.click_element,
                args: [selector] // 传递参数
            });
        });
    };
});